import baseUrl from '@/utils/baseUrl.js' // api接口地址
export default {
  data() {
    return {
      background: {
        backgroundColor: '#fbd220',
      },
      shareInfo: {}, //邀请信息
      percent: 0, //进度
      invitationCode: '',
      url: '',
      show: false,
      type: true, //是否显示刻度
      h5url: '',
      judgeurl: 0, //判断是线上接口还是线下接口
    }
  },
  onLoad(op) {
    if (!op.type) return false
    if (op.type === 'push') {
      this.type = false
    }

  },
  created() {
    this.getUserShareInfo()
    this.getCurrentUsersInviteCode()
  },
  methods: {
    //返回
    returnpage() {
      uni.navigateBack()
    },
    //美图暂时未开始发
    meituClick() {
      this.$refs.uToast.show({
        title: '尽情期待',
        type: 'info'
      })
    },
    //跳转我的好友页面
    achievement() {
      uni.switchTab({
        url: '/pages/friend/friend'
      })
    },
    lxr() {
      uni.navigateTo({
        url: '/pages_userModule/mobileContacts/mobileContacts?inviteCode=' + this.invitationCode
      })
    },
    async getCurrentUsersInviteCode() {
      try {
        const res = await this.$api.me.getCurrentUsersInviteCode()
        console.log(res.data, '邀请码')
        this.invitationCode = res.data
      } catch (e) {
        //TODO handle the exception
      }
    },
    goStrategy(url) {
      uni.navigateTo({
        url: url
      })
    },

    //跳转落地页
    goPage(type) {
      if (baseUrl === 'https://testapi.yzsheng.com') {
        this.h5url = 'https://files.yzsheng.com/shareH5/Qmc_Client_H5/invitation.html?code='
        this.judgeurl = 0
      } else if (baseUrl === 'https://lineapi.yzsheng.com') {
        this.h5url = 'https://files.yzsheng.com/shareH5/Qmc_Client_H5/invitation.html?code='
        this.judgeurl = 1
      }
      if (type === 'WXSceneSession' || type === 'WXSenceTimeline') {
        let code = this.invitationCode
        uni.share({
          provider: 'weixin',
          scene: type,
          type: 0,
          summary: '100%羊毛免费薅，免费洗车！点击领取吧！',
          title: '在吗？好友送你免费洗车券',
          href: this.h5url + code + '&judgeurl=' + this.judgeurl,
          imageUrl: 'https://files.yzsheng.com/client/me/img/logo.png',
          success: function(res) {
            console.log(res)
          },
          fail: function(err) {
            console.log('fail:', err)
            uni.showToast({
              title: '分享失败'
            })
          }
        })
      }
      // console.log(code)
      console.log(type)

    },
    //邀请
    async getUserShareInfo() {
      try {
        const res = await this.$api.me.getUserShareInfo()
        this.shareInfo = res.data

        //判断邀请人数是否超过25人
        if (res.data.shareCount > 25) {
          this.percent = 25 * 4
        } else {
          this.percent = res.data.shareCount * 4
        }
        console.log(res.data)
      } catch (err) {}
    },
  }
}
